package servlet;

import dao.Student;
import hbase.HbaseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/add")
public class AddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        取参数值
//        req.setCharacterEncoding("utf-8");
        String id = req.getParameter("id");
        String name = req.getParameter("name");
        String date = req.getParameter("date");
        String number = req.getParameter("number");
        String semester = req.getParameter("semester");
        String status = req.getParameter("status");

        System.out.println("Data Inserted Successfully");


        ArrayList<Student> studentArrayList = new ArrayList<>();
        Student student = new Student();
        student.setId(id);
        student.setName(name);
        student.setDate(date);
        student.setNumber(number);
        student.setSemester(semester);
        student.setStatus(status);
        studentArrayList.add(student);
//
        HbaseUtil hbaseAddUtil = new HbaseUtil();

        String obj ="";
        try {
         obj =  hbaseAddUtil.insertinfo("niit01","2181","student",studentArrayList);
        }catch (Exception e){
            e.printStackTrace();
        }
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw =  resp.getWriter();
        pw.write("<h1>"+  obj);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

}
